<?php

namespace app\admin\controller\goods;

use Throwable;
use ba\Random;
use app\common\controller\Backend;
use app\admin\model\GoodsCat as dbModel;

class GoodsCat extends Backend
{
    /**
     * @var object
     * @phpstan-var UserModel
     */
    protected object $model;

    

    // 排除字段
    protected string|array $preExcludeFields = ['last_login_time', 'login_failure', 'password', 'salt'];

    protected string|array $quickSearchField = ['name','id'];

    public function initialize(): void
    {
        parent::initialize();
        $this->model = new dbModel();
    }

    /**
     * 查看
     * @throws Throwable
     */
    public function index(): void
    {
        if ($this->request->param('select')) {
            $this->select();
        }

        list($where, $alias, $limit, $order) = $this->queryBuilder();
        $where['shop_id'] = $this->store_id;
        $res = $this->model
 
            ->alias($alias)
            ->where($where)
            ->order($order)
            ->paginate($limit);

        $this->success('', [
            'list'   => $res->items(),
            'total'  => $res->total(),
            'remark' => get_route_remark(),
        ]);
    }

    function goodscatList(){
        $res =  $this->model->where("shop_id",$this->store_id)->field("id,name")->select();
        $this->success('ok', ['list' => $res]);
    }
}